package com.mf.basic;

import com.mf.utils.CommonUtils;
import com.mf.utils.IPUtil;
import jakarta.servlet.http.HttpServletRequest;

/**
 * @Author: lmf
 * @Create: 2024/7/10 13:11
 * Description:
 */
public class BasicKey {
    /**
     * token
     */
    public static final String REDIS_USER_TOKEN = "redis_user_token:";
    /**
     * 刷新token key
     */
    public static final String REDIS_USER_REFRESH_TOKEN = "redis_user_refresh_token:";
    /**
     * 默认值
     */
    public static final String DEFAULT_VALUE = "1";
    /**
     * 验证码前缀
     */
    public static final String MOBILE_CAPTCHA = "system:captcha:";

    /**
     * 获取缓存的Key
     */
    public static String getCaptchaKey(HttpServletRequest request, String type) {
        String requestIp = IPUtil.getRequestIp(request);
        // 获取浏览器信息(类似唯一标识)
        String headerAgent = request.getHeader("User-Agent");
        return BasicKey.MOBILE_CAPTCHA + CommonUtils.MD5(requestIp + headerAgent + type);
    }
}
